  // 评论功能
$(function () {
    // let date = new Date().toLocaleString()
    function randarAjax() {
      $.ajax({
        type: 'get',
        url: '/admin/comments',
          success: function (res) {
              //   var tags = template('table-tpl', res)
              if (res.status === 0) {
                let str = ``
                  res.data.forEach(item => {
                    str += `
                    <tr>
                        <td>${item.id}</td>
                        <td>${item.uname}</td>
                        <td>${item.content}</td>
                        <td>${item.cdate}</td>
                        <td>
                        <!-- <button data-id="${item.id}" type="button" class="layui-btn layui-btn-xs edit">
                            编辑
                        </button> -->
                        <button data-id="${item.id}" type="button" class="layui-btn layui-btn-xs layui-btn-danger delete">
                            删除
                        </button>
                        </td>
                  </tr>
                    `
                 });
              $('.layui-table tbody').html(str)
              }
        }
      })
    }
  
    randarAjax()
  
    // 删除评论
    $('.layui-table tbody').on('click', '.delete', function (e) {
      var id = $(e.target).data('id')
      layer.confirm('确认要删除吗？', function (index) {
        $.ajax({
          type: 'delete',
          url: '/admin/comments/' + id,
          success: function (res) {
              if (res.status === 0) {
              // 关闭窗口
              layer.close(index)
              // 刷新类别
              randarAjax()
            }
          }
        })
      })
    })
  })
  
  